#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {
    int n;
    cin >> n;
    while (n--) {
        int Z_len = 0;
        int H_len = 0;
        int FX = 1;
        string middle;
        cin >> middle;

        for (int i = 0; i < middle.length(); i++) {
            if (middle[i] == 'R') {

                FX = FX % 4 + 1;
            }
            else if (middle[i] == 'L') {

                if (FX == 1)
                    FX = 4;
                else
                    FX--;
            }
            else {
                //L100R50R10
                int num = 0;
                for (; (i < middle.length()) && (middle[i] != 'R' && middle[i] != 'L'); i++)
                    num = num * 10 + middle[i] - '0';
                i--;
                if (FX == 1)
                    Z_len += num;
                else if (FX == 2)
                    H_len += num;
                else if (FX == 3)
                    Z_len -= num;
                else if (FX == 4) {
                    H_len -= num;
                }

            }
        }
        double result = sqrt(Z_len * Z_len + H_len * H_len);
        printf("%0.2f\n", result);
    }
    return 0;
}